package year2021.month08910;

import java.util.Optional;

public class OptionalTest {
    public static void main(String[] args){
        Man man = null;
        Integer age = Optional.ofNullable(man).map(Man::getAge).orElse(0);
        System.out.println(age);

        man = new Man();
        age = Optional.ofNullable(man).map(Man::getAge).orElse(0);
        System.out.println(age);

        man.setAge(10);
        age = Optional.ofNullable(man).map(Man::getAge).orElse(0);
        System.out.println(age);
    }
}

class Man {
    private String name;
    private Integer age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}